<template>
  <div>
    <!-- 顶部logo 和 逛一逛 -->
    <div class="Login_title">
      <van-nav-bar>
        <!-- 左边 -->
        <template #left>
          <div class="title_logo">
            <img src="../assets/images/home_active.png" alt="" />
          </div>
          <div class="title_logo_wenzi">Luckin Coffee</div>
        </template>
        <!-- 右边 -->
        <template v-slot:right>
          <div class="title_right_btn">先逛一逛</div>
        </template>
      </van-nav-bar>
    </div>

    <!-- 页面内容 -->
    <div class="content">
      <!-- 界面文字部分 -->
      <div class="content_box">
        <div class="content_chinese">找回密码!</div>
        <div class="content_EngList">FindPassword</div>
      </div>
      <!-- 表单位置 -->
      <div class="content_table">
        <van-form>
          <van-field
            v-model="MyEmail"
            type="email"
            name="用户名"
            label="邮箱"
            placeholder="邮箱"
          />
          <van-field
            v-model="msm"
            center
            clearable
            label="验证码"
            placeholder="请输入验证码"
          >
            <template #button>
              <van-button
                @click="emailValidCode()"
                size="small"
                color="blue"
                type="primary"
                >发送验证码</van-button
              >
            </template>
          </van-field>
          <div class="content_login"><span @click="goLogin">已有账号? 登录一下吧</span></div>
          <div style="margin: 30px 15px">
            <van-button
              @click="checkValidCode()"
              round
              block
              color="blue"
              type="info"
              native-type="submit"
              >下一步</van-button
            >
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Retrievethepassword",
  data() {
    return {
      // 邮箱
      MyEmail: "",

      // 验证码
      msm: "",
    };
  },
  methods: {
    // 获取验证码
    emailValidCode() {
      //   获取邮箱验证码接口
      //   请求地址：http://www.kangliuyong.com:10002/emailValidCode
      //   请求类型： POST
      //   请求参数： {
      //     appkey: 你的appkey,
      //     email: 接收验证码邮箱
      //   }
      this.axios({
        method: "POST",
        url: "/emailValidCode",
        data: {
          email: this.MyEmail,
        },
      })
        .then((res) => {
          
        })
        .catch((err) => {
          
        });
    },

    // 验证码验证 成功则下一步
    checkValidCode() {
      this.axios({
        method: "POST",
        url: "/checkValidCode",
        data: {
          validCode: this.msm,
        },
      })
        .then((res) => {
          this.$toast(res.data.msg);
          if (res.data.code === "K003") {
            return;
          }
          if (res.data.code === "K001") {
            setTimeout(() => {
              this.$router.push({ name: "FindPasswordnext" });
            }, 1000);
          }
          
        })
        .catch((err) => {
          
        });
    },
    // 跳转至登录页面
    goLogin() {
      this.$router.push({ name: "Login" });
    },
  },
};
</script>

<style lang="less" scoped>
// 顶部logo 和 逛一逛 样式
.title_logo {
  width: 45px;
  height: 45px;
  img {
    width: 100%;
    height: 100%;
  }
}
.title_logo_wenzi {
  font-size: 18px;
  color: #333;
}
.title_right_btn {
  color: blue;
  font-weight: bold;
  font-size: 13px;
}

// 界面文字部分
.content {
  position: fixed;
  top: 50px;
  bottom: 0;
  left: 0;
  right: 0;
  padding-top: 100px;

  // 界面文字部分
  .content_box {
    padding-left: 20px;
    .content_chinese {
      font-size: 30px;
      font-weight: bolder;
      color: #555;
      margin-bottom: 20px;
    }
    .content_EngList {
      font-size: 14px;
      color: #999;
    }
  }
  .content_table {
    margin-top: 30px;
    .content_login {
      padding-top: 15px;
      text-align: right;
      padding-right: 20px;
      span {
        padding: 5px 10px;
      }
    }
  }
}
</style>